#include "Channel.h"
/*
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Security ip="10.10.108.129" date="1365580205000" digitalseal="2e0d1b3826449b75110736bee07427d9"/>
<Service business="AAS" function="getMonitorCenterList"/>	
<RequestInfo querytype="List" page="" pagesize="">		
<GetMonitorCenterInfo uid="root" token="4a2925d9a21219da053023b4d347f8c5" mcflag="001"/>	
</RequestInfo>
</Request>
*/
/*
<?xml version="1.0" encoding="UTF-8"?>
<Result><ResultInfo resultcode="200" errormessage="OK"/>
<Service business="AAS" function="getMonitorCenterList"/>
<ResultData querytype="List">
<MonitorCenter id="1" name="" mcflag="001" parentid="0" type="0"/>
<MonitorCenter id="33" name="NS" mcflag="001001" parentid="1" type="0"/>
<MonitorCenter id="35" name="BH" mcflag="001001001" parentid="33" type="0"/>
<MonitorCenter id="34" name="SK" mcflag="001002" parentid="1" type="0"/>
</ResultData>
</Result>
*/

ChannelReqReader::ChannelReqReader(void)
{
}


ChannelReqReader::~ChannelReqReader(void)
{
}

int ChannelReqReader::read(CommRequest& userLogin)
{
	ChannelReq& channelReq = static_cast<ChannelReq&>(userLogin);
	TiXmlElement* pChild = m_pRootEle->FirstChildElement("RequestInfo");
	const char* strType = pChild->Attribute("querytype");
	TiXmlElement* pChild2 = pChild->FirstChildElement("GetChannelsInfo");
	channelReq.uid = pChild2->Attribute("uid");
	channelReq.token = pChild2->Attribute("token");
	channelReq.mcflag = pChild2->Attribute("mcflag");

	return 0;
}

ChannelRepWriter::ChannelRepWriter(void)
{
}


ChannelRepWriter::~ChannelRepWriter(void)
{
}
int ChannelRepWriter::doWrite(const CommReply& rep,string& reply)
{
	const ChannelRep& channelRep = static_cast<const ChannelRep&>(rep);

	TiXmlElement ResultInfoEle("ResultInfo");
	ResultInfoEle.SetAttribute("resultcode",channelRep.status);
	ResultInfoEle.SetAttribute("errormessage","OK");

	m_pRootNode->InsertEndChild(ResultInfoEle);

	TiXmlElement ServiceEle("Service");
	ServiceEle.SetAttribute("business","AAS");
	ServiceEle.SetAttribute("function","getChannelPage");
	m_pRootNode->InsertEndChild(ServiceEle);

	TiXmlElement ResultDataEle("ResultData");
	ResultDataEle.SetAttribute("querytype","list");

	TiXmlNode* pResultDataNode = m_pRootNode->InsertEndChild(ResultDataEle);

	int size = channelRep.veChannel.size();
	for (int i=0;i<size;i++)
	{
		TiXmlElement channelEle("Channel");
		channelEle.SetAttribute("id",channelRep.veChannel[i].id);
		channelEle.SetAttribute("uid",channelRep.veChannel[i].uid);
		channelEle.SetAttribute("name",channelRep.veChannel[i].name);
		channelEle.SetAttribute("frontid",channelRep.veChannel[i].frontid);
		channelEle.SetAttribute("frontname",channelRep.veChannel[i].frontname);
		channelEle.SetAttribute("mcflag",channelRep.veChannel[i].mcflag);
		channelEle.SetAttribute("type",channelRep.veChannel[i].type);
		channelEle.SetAttribute("mode",channelRep.veChannel[i].mode);
		channelEle.SetAttribute("frontendState",channelRep.veChannel[i].frontendState);
		channelEle.SetAttribute("onlineStatus",channelRep.veChannel[i].onlineStatus);
		channelEle.SetAttribute("rcurl",channelRep.veChannel[i].rcurl);

		TiXmlNode* pAuthNode = pResultDataNode->InsertEndChild(channelEle);
	}

	reply << *m_pDoc;

	return 0;
}
